package me.goldze.mvvmhabit.widget;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import me.goldze.mvvmhabit.R;


/**
 * Created by i7-1 on 2018/12/3.
 */

public class MyToolBar extends FrameLayout {
    public MyToolBar(Context context) {
        super(context);
    }

    public MyToolBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }


    public MyToolBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(final Context context, AttributeSet attrs) {

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.head);
        boolean showR = ta.getBoolean(R.styleable.head_showR, false);
        String title = ta.getString(R.styleable.head_title);
        ta.recycle();

        View inflate = LayoutInflater.from(context).inflate(R.layout.my_toolbar, this, false);
        this.addView(inflate);

        inflate.findViewById(R.id.back).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Activity activity = (Activity) context;
                activity.finish();
            }
        });
        ((TextView) inflate.findViewById(R.id.title)).setText(title);


    }


}
